package com.service.serviceImpl;

import com.Result.UserResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.UserMapper;
import com.pojo.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UseServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        List<User> user = userMapper.findAll();
        return user;
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public UserResult<User> findPage(int page, int size) {
        //开始分页
        PageHelper.startPage(page,size);
        //查询数据
        List<User> userList = userMapper.findByPage();
        //使用PageInfo包装结果
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        UserResult<User> result = new UserResult<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return result;
    }
}
